<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>Document</title>
</head>
<body>
	<div id="box">
		<p><input type="checkbox" /> 选择</p>
		<p><input type="checkbox" /> 选择</p>
		<p><input type="checkbox" /> 选择</p>
		<p><input type="checkbox" /> 选择</p>
		<p><input type="checkbox" /> 选择</p>
		<p><input type="checkbox" /> 选择</p>
	</div>

	<input type="button"  value="选择" id="btn" />

	<script type="text/javascript">
		var inputs = document.getElementById("box").getElementsByTagName("input");
		inputs[0].checked = "checked";
		var btn = document.getElementById("btn");

		//信号量
		var state = 0; //都没选，1都选了
		//点击按钮的事件
		btn.onclick = function(){
			//信号量如果是0，那么就要变为1 ； 如果是1，就要变为0
			state = state == 0 ? 1 : 0;
			//checked的状态，是""或者是"checked"
			var str = state == 0 ? "" : "checked";
			//按钮文本
			this.value = state == 0 ? "全选" : "都不选";

			//批量设置所有复选框
			for (var i = 0; i < inputs.length; i++) {
				inputs[i].checked = str;
			}
		}
	</script>
</body>
</html>